package com.salestax.core.tests;

import java.io.StringReader;
import java.math.BigDecimal;

import junit.framework.TestCase;

import com.salestax.core.ShoppingList;
import com.salestax.core.io.ShoppingListReader;

public class TestIO extends TestCase{

	public void testFirstCase(){
		StringReader reader = new StringReader("1 book at 12.49\n1 music CD at 14.99\n1 chocolate bar at 0.85");
		ShoppingListReader shoppingListReader = new ShoppingListReader(reader);
		ShoppingList shoppingList = shoppingListReader.getShoppingListFromReader();
		assertEquals("29.83", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("1.50", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}
	
	public void testSecondCase(){
		StringReader reader = new StringReader("1 imported bottle of perfume at 27.99\n1 bottle of perfume at 18.99\n1 packet of headache pills at 9.75\n1 box of imported chocolates at 11.25\n");
		ShoppingListReader shoppingListReader = new ShoppingListReader(reader);
		ShoppingList shoppingList = shoppingListReader.getShoppingListFromReader();
		assertEquals("6.70", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("74.68", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
	}
	
	public void testThirdCase(){
		StringReader reader = new StringReader("1 imported box of chocolates at 10.00\n1 imported bottle of perfume at 47.50");
		ShoppingListReader shoppingListReader = new ShoppingListReader(reader);
		ShoppingList shoppingList = shoppingListReader.getShoppingListFromReader();
		assertEquals("65.15", shoppingList.totalCost().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		assertEquals("7.65", shoppingList.totalTax().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
		
	}
}
